// useUpdateEffect 用法等同于 useEffect，但是会忽略首次执行，只在依赖更新时执行。
import { useRef, useEffect } from 'react';

const useUpdateEffect = (hook) => (effect, deps) => {
  const isMounted = useRef(false);

  hook(() => {
    return () => {
      isMounted.current = false;
    };
  }, []);

  hook(() => {
    if (!isMounted.current) {
      isMounted.current = true;
    } else {
      return effect();
    }
  }, deps);
};

export default useUpdateEffect(useEffect);
